<template>
	<view>
        <uni-popup ref="reworkPopup" height="200px" type="center" :animation="false">
			<view class="mypopup">
				<view class="mypopup__head">
					<image src="../../static/img/icon-clock.png"></image>
					<text>返工</text>
				</view>
				<view class="mypopup__body">
					<picker mode="selector" :range="reworkReason" :value="reasonIndex" range-key="Name" @change="ChangeReason">
						<AGInput customStyle="margin-top:0px;" readonly dropdown placeholder="原因代码" :value="reworkReason[reasonIndex].Name" />
					</picker>
					<view class="ag-divider"></view>
					<AGInput textarea placeholder="备注" @change="ChangeReworkRemark" />
					<view class="mypopup__footer">
						<button class="cu-btn lg primary" @click="onReworkSubmit">确定</button>
						<button class="cu-btn lg primary plain" @click="Cancel">取消</button>
					</view>
				</view>
		    </view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@dcloudio/uni-ui/lib/uni-popup/uni-popup';
	import AGInput from '../AGInput/index'
	import constant from '@/common/constant'
	export default {
		components: {
			AGInput,
			uniPopup
		},
		data(){
			return{
				reworkReason:[],
				reasonIndex:0,
				reworkRemark:""
			}
		},
		mounted() {
			this.ReasonCodeListAsync(constant.WORDER_rework_code);
		},
		methods:{
			onReworkSubmit(e){
				let parm = {
					Remark:this.reworkRemark,
					ReasonId:this.reworkReason[this.reasonIndex].ReasonCodeId
				};
				this.$emit("onReworkSubmit",parm);
			},
			Cancel(e){
				this.closePoPup();
			},
			ChangeReworkRemark(e){
				console.log(e);
				this.reworkRemark = e;
			},
			ChangeReason(e){
				this.reasonIndex = e.detail.value;
			},
			openPoPup() {
				this.$refs.reworkPopup.open();
			},
			closePoPup() {
				this.$refs.reworkPopup.close();
			},
			ReasonCodeListAsync(ReasonCodeType) {
				let UserPhone = this.UserInfo.mobile;
				let token = this.UserInfo.RetId
				this.workorderdetailservice.ReasonCodeListAsync(UserPhone, ReasonCodeType, token)
				.then(result=>{
					 console.log(result);
					 if (result.RetBool == true) {
					 	let data = JSON.parse(result.RetObject);
					 	this.reworkReason = data;
					 } else {
					 	uni.showToast({
					 		title: result.RetMsg,
					 		icon: "none"
					 	});
					 }
				 });
			},
			
		}
	}
</script>

<style lang="scss">
	
</style>